<?php

namespace App\Http\Controllers\admin;

use App\Dao\CategoryDao;
use App\Dao\GoodsDao;
use App\Services\Code;

class GoodsController extends BaseController
{
    public function goods()
    {
        if(getIsHasPage()){
            return  Code::message('',200,GoodsDao::goods(request()->all()));
        }
        $categorys = CategoryDao::categorysWithNotPage();
        return view('admin.goods.goods',[
            'categoryData'=>$categorys
        ]);
    }

    public function add()
    {
        if(isPost()){
            $params = request()->all();
            GoodsDao::add($params);
            return  Code::message();
        }
        $categorys = CategoryDao::categorysWithNotPage();
        return view('admin.goods.add',[
            'categoryData'=>$categorys
        ]);
    }


    public function edit()
    {
        $params = request()->all();
        if(isPost()){
            GoodsDao::edit($params);
            return  Code::message();
        }
        $categorys = CategoryDao::categorysWithNotPage();
        $info = GoodsDao::info(['goods_id'=>$params['goods_id']]);
        return view('admin.goods.edit',[
            'categoryData'=>$categorys,
            'info'=>$info
        ]);
    }
}
